# coding:utf-8
import random
class Rule():
    def __init__(self, name, sex, blood=100, bodyarmor=None):
        self.name = name
        self.sex = sex
        self.blood = blood
        self.body_armor = bodyarmor
        self.room = None
    def attack(self, other):
        if self.room == other.room:
            if self != other:
                if self.blood > 0 and other.blood > 0:
                    oligemia = 5 if other.bodyarmor else 10
                    other.blood -= oligemia
                    print(f"{self.name}攻击{other.name} {oligemia}点血量\t{self.name}当前血量:{other.blood}")
                else:
                    print("其中一方已死亡，不能攻击")
                    exit()
            else:
                print("你不能攻击自己")
        else:
            print("目标不在同一个房间")
class Room():
    def __init__(self, name):
        self.member = []
        self.name = name
    def join(self, rule):
        if rule.room == None:
            if len(self.member) < 2:
                self.member.append(rule)
                rule.room = self.name
            else:
                print("房间已经有两个人了")
        else:
            print("你已经加入房间了")
rules = dict()
rooms = dict()
while True:
    print("请选择：1.创建角色\t2.创建房间\t3.加入房间\t4.开始战斗\t5.退出")
    enter_number = input("请输入你的选择:\t")
    if enter_number.isdigit():
        enter_number = int(enter_number)
        if 1 <= enter_number <= 5:
            if enter_number == 1:
                name, sex = input("请输入你的名字和性别，空格隔开:\n").split()
                rules[name] = Rule(name, sex)
                def_blood = input("请输入自定义血量:\n")
                if def_blood.isdigit():
                    rules[name].blood = int(def_blood)
                    print(f"自定义成功，用户{name}当前血量{rules[name].blood}")
                else:
                    print(f"自定义失败，用户{name}当前血量{rules[name].blood}")
                wear_bodyarmor = input("请输入y准备防弹衣\n")
                if wear_bodyarmor == "y":
                    rules[name].bodyarmor = 1
            elif enter_number == 2:
                name = input("请输入房间的名字\n")
                rooms[name] = Room(name)
            elif enter_number == 3:
                print(f"当前角色有{rules.keys()},当前房间有{rooms.keys()}")
                rname = input("请输入要加入的角色:\n")
                mname = input("请输入要加入的房间：\n")
                rooms[mname].join(rules[rname])
            elif enter_number == 4:
                print(f"当前房间有{rooms.keys()}")
                room_name = input("请输入房间的名字\n")
                if len(rooms[room_name].member) == 2:
                    while True:
                        rooms[room_name].member[0].attack(rooms[room_name].member[1])
                        rooms[room_name].member[1].attack(rooms[room_name].member[0])
                else:
                    print(f"房间{room_name}人数不足2个人，对战发起失败！")
                    continue
            elif enter_number == 5:
                print("退出对战")
                break
        else:
            print("输入错误，请输入1-5数字！")
    else:
        print("输入错误，请输入1-5数字！")